/*
   Part of the libABF project.

   libABF is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
#ifndef ABF_FORMAT_LEX_H
#define ABF_FORMAT_LEX_H

#include "abf_flat.h"

#include "abf_util.h"
#include <stdio.h>

struct abf_lex_config
{
    const char* StartComment;
    const char* EndComment;

    const char* StartList;
    const char* EndList;

    const char* StartStruct;
    const char* EndStruct;

    const char* StartString;
    const char* EndString;

    const char* Identifier;
};
typedef struct abf_lex_config abf_lex_config_t;

typedef enum
{
    ABF_LEX_UNKNOWN = -1,
    ABF_LEX_EOF = 0,
    ABF_LEX_START_STRUCT,
    ABF_LEX_END_STRUCT,
    ABF_LEX_IDENTIFIER,
    ABF_LEX_ASSIGN,
    ABF_LEX_START_LIST,
    ABF_LEX_LIST_SEPARATOR,
    ABF_LEX_END_LIST,
    ABF_LEX_STRING,
    ABF_LEX_INT,
    ABF_LEX_FLOAT,
    ABF_LEX_ERROR
} abf_lex_token;

struct abf_lex_state
{
    abf_lex_config_t* Config;
    char* Buffer;
    char* Ptr;
    uint32_t Capacity;
    uint32_t Size;
    abf_lex_token Token;
    double AsFloat;
    int32_t AsInt;
    char* AsString;
};
typedef struct abf_lex_state abf_lex_state_t;

abf_lex_state_t* abf_lex_create(abf_lex_config_t* lex_config);
void abf_lex_destroy(abf_lex_state_t* state);

abf_status abf_lex_read(abf_lex_state_t* state, const char* filename);
abf_lex_token abf_lex_next_token(abf_lex_state_t* state);

#endif /* ABF_FORMAT_LEX_H */

